package cate.common.table.activity.base;

import cate.common.table.ERow;
import cate.common.table.XSSFRowWrap;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

@NoteClass("活动商店配置")
public class ShopActivityBaseRow extends ERow {
    @NoteField("购买类型")
    public int type;
    @NoteField("充值项ID")
    public int payId;
    @NoteField("物品消耗")
    public String costStr;
    @NoteField("奖励")
    public String rewardStr;
    @NoteField("限购次数")
    public int limit;
    @NoteField("重置类型")
    public int resetType;

    @NoteField("免费")
    public static final int SHOP_TYPE_FREE = 0;
    @NoteField("消耗道具")
    public static final int SHOP_TYPE_ITEM_COST = 1;
    @NoteField("支付")
    public static final int SHOP_TYPE_PAY = 2;

    @NoteField("开服天数")
    public int openDay;

    @Override
    public void parse(XSSFRowWrap xrw) {
        super.parse(xrw);
        id = xrw.getInteger("ID");
        type = xrw.getInteger("购买类型", -1);
        payId = xrw.getInteger("充值项ID", 0);
        costStr = xrw.getString("物品消耗", "");
        rewardStr = xrw.getString("商品");
        limit = xrw.getInteger("限购次数", -1);
        resetType = xrw.getInteger("重置类型", 0);
        openDay = xrw.getInteger("开服天数", 0);
    }

    @Override
    public void decode() {
        super.decode();
        if (rewardStr == null || rewardStr.isEmpty()) {
            getContext().warningOnSheetLoading(parent.parent.getFileName(),
                    parent.getSheetName(),
                    "ID=" + id + " 未配置商品!");
        }
        if (type == SHOP_TYPE_FREE && limit == -1) {
            getContext().warningOnSheetLoading(parent.parent.getFileName(),
                    parent.getSheetName(),
                    "ID=" + id + " 购买类型 免费 但是没有配置限购次数!");
        }
        switch (type) {
            case SHOP_TYPE_FREE: {
                if (costStr != null && !costStr.isEmpty()) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 免费 但是配置了物品消耗!");
                }
                if (payId > 0) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 免费 但是配置了充值项ID!");
                }
            }
                break;
            case SHOP_TYPE_ITEM_COST: {
                if (costStr == null || costStr.isEmpty()) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 消耗道具 但是没有配置物品消耗!");
                }
                if (payId > 0) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 消耗道具 但是配置了充值项ID!");
                }
            }
                break;
            case SHOP_TYPE_PAY: {
                if (costStr != null && !costStr.isEmpty()) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 支付 但是配置了物品消耗!");
                }
                if (payId == 0) {
                    getContext().warningOnSheetLoading(parent.parent.getFileName(),
                            parent.getSheetName(),
                            "ID=" + id + " 购买类型 支付 但是没有配置充值项ID!");
                }
            }
                break;
            default: {
                getContext().warningOnSheetLoading(parent.parent.getFileName(),
                        parent.getSheetName(),
                        "ID=" + id + " 配置了错误的购买类型!");
            }
                break;
        }
    }
}
